    $(function(){
        layui.use(['layer','form'], function(){
            var form = layui.form;
            var layer = layui.layer;
            //自定义验证规则
            form.verify({
                phone:[/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/, '请输入正确的手机号'],
                password: [/(.+){6,12}$/, '密码必须6到12位'],
            });
            // 监听提交
            form.on('submit(formDemo)', function (data) {
                var action = data.form.action;//表单提交URL地址
                // console.log(JSON.stringify(data.field));//表单数据
                $.post(action, data.field, function (obj) {
                    //根据返回结果作出相应处理
                    if (obj.code == 400) 
                    {
                        layer.msg(obj.status+':'+obj.msg)
                    }else if(obj.code == 401)
                    {
                        layer.msg(obj.status+':'+obj.msg)
                    }else if(obj.code == 200){
                        layer.msg(obj.status+':'+obj.msg,{time:1000,icon:1}, function(){
                            window.location.href = '/Xindex';
                        })
                    }
                },'json');
                return false;//注释掉这行代码后，表单将会以普通方式提交表单，否则以ajax方式提交表单
            });
        })
    })
